﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Reflection;

namespace ADO.NET.Samples.Common
{
    /// <summary>
    /// Forms data provider
    /// </summary>
    public class FormsDataBindingList : BindingList<FormInfo>
    {
        public FormsDataBindingList()
        {
            InitializeData();
        }

        /// <summary>
        /// Initialize data
        /// </summary>
        private void InitializeData()
        {
            var attrType = typeof(FormDescriptionAttribute);
            var assem = Assembly.GetExecutingAssembly();
            var types = assem.GetTypes();
            foreach (var type in types)
            {
                if (type.IsClass && type.IsDefined(attrType, true))
                {
                    var attr = type.GetCustomAttributes(attrType, true)[0] as FormDescriptionAttribute;
                    this.Add(new FormInfo(attr.FormTitle, attr.FormDesc, type.AssemblyQualifiedName));
                }
            }
        }
    }

}
